from typing import Optional, List, Dict
from pydantic import BaseModel, Field
from datetime import datetime


class UploadImage(BaseModel):
    tags: Optional[List[str]] = []
    folder: int
    upload_time: Optional[datetime] = Field(default_factory=lambda: datetime.now())
    width: Optional[int] = None
    height: Optional[int] = None
    size: int
    hash: str
    format: str


class ImageModel(UploadImage):
    id: int
    update_time: Optional[datetime] = None
    url: Optional[str] = None

    class Config:
        from_attributes = True


class UpdateImageTags(BaseModel):
    id: int
    tags: List[str]


class ImagePagination(BaseModel):
    page: int
    per_page: int
    folder: int
    total: int
    images: List[Dict]


class CreateImageFolder(BaseModel):
    name: str
    description: str


class UpdateImageFolder(CreateImageFolder):
    id: int


class ImageFolder(CreateImageFolder):
    id: int
    created_time: datetime
    updated_time: Optional[datetime] = None
    count: int
    size: int
    operable: bool
    cover: Optional[str] = None

    class Config:
        from_attributes = True
